package com.hui.stock.controller;

import com.hui.stock.pojo.domain.*;
import com.hui.stock.pojo.entity.StockRtInfo;
import com.hui.stock.service.StockService;
import com.hui.stock.vo.resp.PageResult;
import com.hui.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author: ymh
 * @date: 2024/12/2 16:14
 * @description:股票相关接口控制器
 */
@Api(value = "/api/quot", tags = {"股票相关接口控制器"})
@RestController
@RequestMapping("/api/quot")
public class StockController {
    @Autowired
    private StockService stockService;

    @ApiOperation(value = "获取A股大盘最新有效时间数据", notes = "", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarkerInfo(){
        return stockService.getInnerMarkerInfo();
    }

    @ApiOperation(value = "获取板块最新有效时间的按照交易金额降序排序的前10条数据", notes = "", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getBlockInfo(){
        return stockService.getBlockInfo();
    }

    /**
     * 分页查询股票最新数据，并按照涨幅排序查询
     * @param page
     * @param pageSize
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "1",example = "1"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "10",example = "10")
    })
    @ApiOperation(value = "分页查询股票最新数据，并按照涨幅排序查询", notes = "分页查询股票最新数据，并按照涨幅排序查询", httpMethod = "GET")
    @GetMapping("/stock/all")
    public R<PageResult> getStockPageInfo(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                                                @RequestParam(name = "pageSize",required = false,defaultValue = "20") Integer pageSize){
        return stockService.getStockPageInfo(page,pageSize);
    }

    /**
     * 查询股票最新的前四条按照涨幅降序排序的数据
     * @return
     */
    @ApiOperation(value = "查询股票最新的前四条按照涨幅降序排序的数据", notes = "", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpdownDomain>> getStockRtInfo(){
        return stockService.getStockRtInfo();
    }

    /**
     * 获取当前的有效交易日(开盘时间-->收盘/当前时间)每分钟达到涨跌停股票的数据
     * @return
     */
    @ApiOperation(value = "获取当前的有效交易日(开盘时间-->收盘/当前时间)每分钟达到涨跌停股票的数据", notes = "获取当前的有效交易日(开盘时间-->收盘/当前时间)每分钟达到涨跌停股票的数据", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpdownCount(){
        return stockService.getStockUpdownCount();

    }

    /**
     * 将指定页的股票数据导出到excel表下
     * @param page
     * @param pageSize
     * @param response
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "page", value = "1",example = "1"),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "10",example = "10")
    })
    @ApiOperation(value = "将指定页的股票数据导出到excel表下", notes = "将指定页的股票数据导出到excel表下", httpMethod = "GET")
    @GetMapping("/stock/export")
    public void stockExport(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                            @RequestParam(name = "pageSize",required = false,defaultValue = "20") Integer pageSize,
                            HttpServletResponse response){
        stockService.stockExport(page,pageSize,response);
    }

    /**
     * 统计沪深两市T日和T-1日每分钟的成交量
     * @return
     */
    @ApiOperation(value = "统计沪深两市T日和T-1日每分钟的成交量", notes = "统计沪深两市T日和T-1日每分钟的成交量", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String,List>> getComparedStockTradeAmt(){
        return stockService.getComparedStockTradeAmt();
    }


    /**
     * 统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量
     * @return
     */
    @ApiOperation(value = "统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量", notes = "统计当前时间下（精确到分钟），A股在各个涨跌区间股票的数量", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> stockUpDown(){
        return stockService.getStockUpDownScopeCount();
    }

    /**
     * 查询个股的分时行情数据，统计指定股票T日每分钟的交易数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "查询个股的分时行情数据，统计指定股票T日每分钟的交易数据", notes = "查询个股的分时行情数据，统计指定股票T日每分钟的交易数据", httpMethod = "GET")
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Stock4MinuteDomain>> getStockScreenTimeSharing(@RequestParam(name = "code") String code){
        return stockService.getStockScreenTimeSharing(code);
    }

    /**
     * 查询指定股票每天产生的数据，组装成日K线数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "查询指定股票每天产生的数据，组装成日K线数据", notes = "查询指定股票每天产生的数据，组装成日K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/dkline")
    public R<List<Stock4EvrDayDomain>> getStockScreenDkline(@RequestParam(name = "code") String code){
        return stockService.getStockScreenDkline(code);
    }
    /**
     * 查询指定股票每天产生的数据，组装成周K线数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "查询指定股票每天产生的数据，组装成周K线数据", notes = "查询指定股票每天产生的数据，组装成周K线数据", httpMethod = "GET")
    @GetMapping("/stock/screen/weekkline")
    public R<List<Stock4EvrWeekDomain>> getStockScreenWeekkline(@RequestParam(name = "code") String code){
        return stockService.getStockScreenWeekkline(code);
    }

    /**
     * 获取个股最新分时行情数据
     * @param code
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "", required = true)
    })
    @ApiOperation(value = "获取个股最新分时行情数据", notes = "获取个股最新分时行情数据", httpMethod = "GET")
    @GetMapping("/stock/screen/second/detail")
    public R<StockRtDomain> getStockScreenSecondDetail(@RequestParam(name = "code") String code){
        return stockService.getStockScreenSecondDetail(code);
    }

    /**
     * 个股交易流水行情数据查询--查询最新交易流水，按照交易时间降序取前10
     * @param code 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "个股交易流水行情数据查询--查询最新交易流水，按照交易时间降序取前10", notes = "个股交易流水行情数据查询--查询最新交易流水，按照交易时间降序取前10", httpMethod = "GET")
    @GetMapping("/stock/screen/second")
    public R<List<StockScreenSecondDomain>> getScreenSecondInfos(@RequestParam(name = "code") String code){
        return stockService.getScreenSecondInfos(code);
    }

    /**
     * 获取国外大盘最新有效时间数据
     * @return
     */
    @ApiOperation(value = "获取国外大盘最新有效时间数据", notes = "获取国外大盘最新有效时间数据", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> getOuterMarkerInfo(){
        return stockService.getOuterMarkerInfo();
    }

    /**
     * 根据输入的个股代码，进行模糊查询，返回证券代码和证券名称
     * @param searchStr
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "searchStr", value = "", required = true)
    })
    @ApiOperation(value = "根据输入的个股代码，进行模糊查询，返回证券代码和证券名称", notes = "根据输入的个股代码，进行模糊查询，返回证券代码和证券名称", httpMethod = "GET")
    @GetMapping("/stock/search")
    public R<List<Map<String,Object>>> getStockSearch(@RequestParam(name = "searchStr") String searchStr){
        return stockService.getStockSearch(searchStr);
    }

    /**
     * 个股主营业务查询接口:根据股票编码获取个股主营业务
     * @param code 股票编码
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "code", value = "股票编码", required = true)
    })
    @ApiOperation(value = "个股主营业务查询接口:根据股票编码获取个股主营业务", notes = "个股主营业务查询接口:根据股票编码获取个股主营业务", httpMethod = "GET")
    @GetMapping("/stock/describe")
    public R<StockBusinessDomain> getStockBusiness(@RequestParam(name = "code") String code){
        return stockService.getStockBusiness(code);
    }
}
